package FeatureSelection;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.Arrays;

import Global.DirectoryStructureAndSettingsClass;
import Global.FileExpert;
import Utility.FileUtilityClass;

public class FeatureSelectionManagerClass {
	
	static int[] readSelectedFeaturesFromFile(int contentIndex)
	{
		BufferedReader in;
		int[] featuresList = null;
		
		try {
			in = DirectoryStructureAndSettingsClass.getFileInForTheFile(FileExpert.getDirectoryNameForFeatureSelectionFiles(), FileExpert.getFileNameForSelectedFeaturesFile(contentIndex));
			System.out.println("Diredtory:" + FileExpert.getDirectoryNameForFeatureSelectionFiles()+ "FNAME:" + FileExpert.getFileNameForSelectedFeaturesFile(0));
			featuresList = FileUtilityClass.readIntegersFromAFileToMemory(in);
			if(featuresList!=null)
				Arrays.sort(featuresList);
			in.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		
		return 	featuresList;	
	}
	
	public static FeatureSelectionDataClass getSelectedFeaturesFromFile(int contentIndex)
	{
		FeatureSelectionDataClass featureSelectionData = null;
		int[] selectedFeatures;
		
		selectedFeatures = readSelectedFeaturesFromFile(contentIndex);
		
		if(selectedFeatures != null)
		{
			featureSelectionData = new FeatureSelectionDataClass();
			featureSelectionData.setSelectedFeaturesIndexes(readSelectedFeaturesFromFile(contentIndex), null);
		}		
			
		return featureSelectionData;
	}
}
